﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace Snip
{
    public class IntervalConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            TimeSpan timespan;
            if (value is TimeSpan)
            {
                timespan = (TimeSpan)value;

            }
            else if (value is int)
            {
                timespan = TimeSpan.FromMinutes((int)value);
            }
            else
            {
                return string.Empty;

            }
            StringBuilder sb = new StringBuilder();
            if (timespan.TotalHours >= 1)
            {
                sb.Append(Math.Floor(timespan.TotalHours));
                if (Math.Floor(timespan.TotalHours) == 1)
                {
                    sb.Append(" Hour");
                }
                else
                {
                    sb.Append(" Hours");
                }
            }
            if (timespan.Minutes > 0)
            {
                if (timespan.TotalHours >= 1)
                {
                    sb.Append(' ');
                }
                sb.Append(timespan.Minutes);
                if (timespan.Minutes == 1)
                {
                    sb.Append(" Minute");
                }
                else
                {
                    sb.Append(" Minutes");
                }
            }
            return sb.ToString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }

    public class NotConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return !(bool)value;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}
